// ----------------------------------------------------------------------------
// Extension
// Name: Adaptive filtering extension
// ----------------------------------------------------------------------------
#define _LIBNAME_R_ "ext_adaptive"	//define lib for support old WIN OS

#include "../ExtFilter.h"
#include "../ExtAppLauncher.h" 

#include <wx/stattext.h>
#include <wx/panel.h>
#include <wx/sizer.h>
#include <wx/aui/aui.h>
#include <wx/textctrl.h>

class AdaptiveExt : public ExtFilter
{
public:
	AdaptiveExt(){index = 1;}
public:
	~AdaptiveExt(){wx_dll_cleanup();}
public:
	ExtDescript * GetDescription();
	void startX();
	int GetType();
	void callback(int event_type, int argc, ...);
private:
	int index;
};


void AdaptiveExt::callback(int event_type, int argc, ...)
{
	wxString tmp;
	va_list vl;
    va_start(vl, argc);
	tmp=va_arg(vl, wxString);
	va_end(vl);

	run_wx_gui_from_dll();// create a new thread for GUI
	/*
	roImage * img = this->GetImage();
	unsigned char * data = img->data();
	int w = img->width(), h = img->height();
	if(data)
	{
		double red2Gray   = 0.297;
		double green2Gray = 0.589;
		double blue2Gray  = 0.114;
		

		int x,y;
		for (y = 0; y < h; y++)
			for (x = 0; x < w; x++)
			{
				long pos = (y * w + x) * 3;

				char g = (char) (data[pos] * red2Gray +
								  data[pos+1] * green2Gray +
								  data[pos+2] * blue2Gray);
				data[pos] = data[pos+1] = data[pos+2] = g;
			}
		this->SetImage(new roImage(data, w, h));
	}
	
	*/
	
	wxDialog * dlg = new wxDialog(NULL,-1,"Hello World From DLL",wxDefaultPosition,wxDefaultSize,wxDEFAULT_DIALOG_STYLE,wxDialogNameStr);
	wxPanel *p = new wxPanel(dlg, wxID_ANY);
	wxSizer *sizer = new wxBoxSizer(wxVERTICAL);

		sizer->Add
			   (
				   new wxStaticText
					   (
						   p, wxID_ANY,
						   wxString::Format
						   (
						       "[%s]\n"
							   "This is %d window\n"
							   "Running using %s\n"
							   "wxApp instance is %p, thread ID %ld",
							   tmp,
							   index,
							   wxVERSION_STRING,
							   wxApp::GetInstance(),
							   wxThread::GetCurrentId()
						   )
					   ),
				   wxSizerFlags(1).Expand().Border(wxALL, 10)
			   );

	index++;
	p->SetSizerAndFit(sizer);
 
	wxSizer *fsizer = new wxBoxSizer(wxVERTICAL);
	fsizer->Add(p, wxSizerFlags(1).Expand());
	dlg->SetSizerAndFit(fsizer);
	dlg->SetBackgroundColour(wxColor(200,200,200));
	dlg->Show();
}
void AdaptiveExt::startX()
{
	GetAPI()->_append_to_menu(GetID(), _("Items"), _("Item 1 (event test)"), _("Click on me for test"));
	GetAPI()->_append_to_menu(GetID(), _("Items"), _("Item 1 (event test)"), _("EEEE .. , click more more..."));
}

ExtDescript * AdaptiveExt::GetDescription()
{
      return new ExtDescript(EXT_FILTER, "Adaptive filtering plugin");
}

int AdaptiveExt::GetType()
{
	return EXT_FILTER;
}
//===============================================================
//		Export functions
//===============================================================


//Export functions
int GetExtensionsNum()
{
	return 1;
}

UndefExtension * GetExtension(int index)
{
    return dynamic_cast<UndefExtension*>(new AdaptiveExt());
}

